package thread.sync1;

public class Table {
    private  int beans=20;

    public synchronized int getBean(){//synchronized给方法上锁，每次只能让一个线程进去，阻塞的线程不存在排队顺序
        if (beans==0){
            throw new RuntimeException("没有豆子了！");
        }
        Thread.yield();
         return  beans--;
    }
}
